﻿using System;
using System.Collections.Generic;
using NineRays.WebControls;

public partial class Topo_ImpMonitorIndex_XDZYL_Tree : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            InitPage();
        }
    }
    private void InitPage()
    {
        string[,] str = new string[4, 2] { { "p_neid", "string" }, { "p_strwhere", "string" }, { "p_sort", "string" }, { "p_topcount", "int" } };
        string[] v = new string[] { "", "", "", "0" };
        BLL.Topo.InformationUtilization n = new BLL.Topo.InformationUtilization();
        List<Model.Topo.InformationUtilization> modelList = n.GetModelList("get_all_tbs_rate", str, v, "ALL");
        FlyTreeNode ftn = new FlyTreeNode();
        foreach (Model.Topo.InformationUtilization model in modelList)
        {
            if (model.TYPE == "UNIT")
            {
                ftn = CreateFlyTreeNode(model, "UNIT", true);
                ftvTree.Nodes.Add(ftn);
            }
            else
            {
                if (ftn != null)
                {
                    ftn.ChildNodes.Add(CreateFlyTreeNode(model, "LEAV", false));
                }
            }
        }
    }
    public FlyTreeNode CreateFlyTreeNode(Model.Topo.InformationUtilization model, string nodeType, bool isExpand)
    {
        FlyTreeNode ftn = new FlyTreeNode();
        ftn.Value = model.NODEID;
        //if (model.UTILIZATION.Length > 0)
        //{
        //    // ftn.Text = model.NODENAME + "[<font style='font-weight:bold'>" + model.UTILIZATION + "</font>]";
        //    ftn.Text = model.NODENAME + "&nbsp;&nbsp;" + model.UTILIZATION;
        //}
        //else
        //{
            ftn.Text = model.NODENAME;
        //}
        switch (nodeType.ToUpper())
        {
            case "UNIT":
                ftn.ImageUrl = "~/images/FlyTreeView/area.gif";
                break;
            case "LEAV":
                ftn.ImageUrl = "~/images/FlyTreeView/TBS.gif";
                break;
            default:
                ftn.ImageUrl = "$kde_folder";
                break;
        }
        ftn.Expanded = isExpand;
        ftn.IsCheckbox = true;
        ftn.Attributes["flag"] = model.TYPE;
        ftn.Attributes["laid"] = model.LAID;
        return ftn;
    }
    private void LoopCheckFlyNodeTxt(FlyTreeNode NodeCheck, ref string strAllText, ref string strAllUnitid)
    {
        if (NodeCheck.Checked)
        {
            strAllText = strAllText + "," + NodeCheck.Text;
            strAllUnitid = strAllUnitid + "," + NodeCheck.Value;
        }
        if (NodeCheck.ChildNodes.Count > 0)
        {
            for (int i = 0; i < NodeCheck.ChildNodes.Count; i++)
            {
                LoopCheckFlyNodeTxt(NodeCheck.ChildNodes[i], ref  strAllText, ref strAllUnitid);
            }

        }
    }
}